//
//  HWSaveMoneyExplainCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/6/29.
//  Copyright © 2022 94hwan. All rights reserved.
//

import UIKit

class HWSaveMoneyExplainCell: UITableViewCell {
    var bgView:UIView!
    var titleLabel:UILabel!
    var contentLabel:UILabel!
    var model:HWSaveModeyCardModel? {
        didSet {
            contentLabel.text = model?.content
            let htmlString:NSMutableAttributedString = (model?.content.toHtmlAttributedText() ?? NSMutableAttributedString())
            htmlString.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.clear, range: NSMakeRange(0, 1))
            htmlString.addAttribute(NSAttributedString.Key.font, value: UIFont.systemFont(ofSize: 13*widthScale), range: NSMakeRange(0, htmlString.length))
            htmlString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.colorWithHexString(hexString: "#CCCCCC"), range: NSMakeRange(0, htmlString.length))
            contentLabel.attributedText = htmlString
        }
    }
    class func cellWithTableView(tableView:UITableView) -> (HWSaveMoneyExplainCell) {
        let reUse:String = "HWSaveMoneyExplainCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWSaveMoneyExplainCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWSaveMoneyExplainCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.colorWithHexString(hexString: "#272727")
        
        bgView = UIView()
        bgView.backgroundColor = .colorWithHexString(hexString: "#2E2E2E")
        bgView.layer.cornerRadius = 14*widthScale
        bgView.layer.borderColor = UIColor.colorWithHexString(hexString: "#454545").cgColor
        bgView.layer.borderWidth = 1
        contentView.addSubview(bgView)
        
        titleLabel = HWLabel.createBoldLabel(title: "省钱卡说明", color: "#CCCCCC", font: 16*widthScale)
        bgView.addSubview(titleLabel)
        
        contentLabel = HWLabel.createLabel(title: "", color: "#CCCCCC", font: 13*widthScale)
        bgView.addSubview(contentLabel)
    }
    
    func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
            make.left.equalTo(18*widthScale)
            make.right.equalTo(-18*widthScale)
            make.top.equalTo(18*widthScale)
            make.bottom.equalTo(-40*widthScale)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.top.equalTo(18*widthScale)
            make.height.equalTo(23*widthScale)
        }
    
        contentLabel.snp.makeConstraints { make in
            make.left.equalTo(18*widthScale)
            make.right.equalTo(-18*widthScale)
            make.top.equalTo(titleLabel.snp.bottom).offset(25*widthScale)
            make.bottom.equalTo(-18*widthScale)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
